#include <iostream>
#include <vector>
#include <numeric>
using namespace std;

class Solution {
	const int MAXN = 50;
	vector<vector<int>> gh;
	vector<vector<vector<int>>> ts;
	vector<int> prices, lca, father, times, parent;
	vector<bool> vis;

	int find(int x)
	{
		return x == father[x] ? x : father[x] = find(father[x]);
	}

	void tarjan(int u, int p)
	{
		vis[u] = true;
		parent[u] = p;
		for (auto v : gh[u]) {
			if (v != p) {
				tarjan(v, u);
				for (auto p : ts[v]) {
					if (vis[p[0]]) {
						lca[p[1]] = find(p[0]);
					}
				}
				father[v] = u;
			}
		}
	}

        void tarjan2(int u, int p)
	{
		vis[u] = true;
		parent[u] = p;
		for (auto v : gh[u]) {
			if (v != p) {
				tarjan2(v, u);
			}
		}
                for(auto p : ts[u]){
                        if(vis[p[0]]){
                                lca[p[1]] = find(p[0]);
                        }
                }
                father[u] = p;
	}

	void dfs(int u, int p)
	{
		for (auto v : gh[u]) {
			if (v != p) {
				dfs(v, u);
				times[u] += times[v];
			}
		}
	}

	int no = 0, yes = 0;
	void dp(int u, int p)
	{
		int no_cast = prices[u] * times[u];
		int yes_cast = (prices[u] / 2) * times[u];
		for (auto v : gh[u]) {
			if (v != p) {
				dp(v, u);
				no_cast += min(no, yes);
				yes_cast += no;
			}
		}
		no = no_cast;
		yes = yes_cast;
	}

    public:
	int minimumTotalPrice(int n, vector<vector<int>> &edges, vector<int> &price, vector<vector<int>> &trips)
	{
		prices.resize(n + 1, 0);
		for (int i = 0; i < n; i++) {
			prices[i + 1] = price[i];
		}

		gh.resize(n + 1);
		for (auto e : edges) {
			gh[e[0] + 1].push_back(e[1] + 1);
			gh[e[1] + 1].push_back(e[0] + 1);
		}

		ts.resize(n + 1);
		int id = 0;
		for (auto q : trips) {
			ts[q[0] + 1].push_back({ q[1] + 1, id });
			ts[q[1] + 1].push_back({ q[0] + 1, id });
			id++;
		}

		vis.resize(n + 1, false);
		lca.resize(trips.size(), 0);
		parent.resize(n + 1, 0);
		father.resize(n + 1, 0);
		iota(father.begin(), father.end(), 0);
		tarjan2(1, 0);

		times.resize(n + 1, 0);
		id = 0;
		for (auto p : trips) {
			int u = p[0] + 1;
			int v = p[1] + 1;
			int c = lca[id];
			int fc = parent[c];
			times[u]++;
			times[v]++;
			times[c]--;
			times[fc]--;
			id++;
		}
		dfs(1, 0);

		dp(1, 0);

		return min(no, yes);
	}
};

int main()
{
	// int n = 4;
	// vector<vector<int>> edges = { { 0, 1 }, { 1, 2 }, { 1, 3 } };
	// vector<vector<int>> trips = { { 0, 3 }, { 2, 1 }, { 2, 3 } };
	// vector<int> price = { 2, 2, 10, 6 };
	int n = 2;
	vector<vector<int>> edges = { { 0, 1 } };
	vector<int> price = { 2, 2 };
	vector<vector<int>> trips = { { 0, 0 } };
	cout << Solution().minimumTotalPrice(n, edges, price, trips) << endl;
	return 0;
}